<template>
  <div>
    <!-- 面包屑区域 开始 -->
    <el-breadcrumb separator="/">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 面包屑区域 结束 -->
    <!-- 卡片区域 开始 -->
    <el-card>
      <!-- 输入框区域 开始 -->
      <el-input
        placeholder="请输入内容"
        class="input-with-select"
        style="width: 40%"
      >
        <el-button slot="append" icon="el-icon-search"></el-button>
      </el-input>
      <!-- 输入框区域 结束 -->
      <!-- 表格区域 开始 -->
      <el-table :data="ordersList" border stripe="">
        <el-table-column label="#" type="index"></el-table-column>
        <el-table-column label="订单编号" prop="order_number"></el-table-column>
        <el-table-column
          label="订单价格"
          prop="order_price"
          width="100px"
        ></el-table-column>
        <el-table-column label="是否付款" width="150px">
          <template v-slot="{ row }">
            <el-tag v-if="row.order_pay === '0'" type="danger" effect="dark"
              >未支付</el-tag
            >
            <el-tag v-else type="success" effect="dark">已支付</el-tag>
          </template>
        </el-table-column>
        <el-table-column
          label="是否发货"
          prop="is_send"
          width="100px"
        ></el-table-column>
        <el-table-column label="下单时间">
          <template v-slot="{ row }">
            {{ row.create_time | formDate }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template>
            <el-button
              type="primary"
              icon="el-icon-edit"
              size="mini"
              @click="editDialogVisible = true"
            ></el-button>
            <el-button
              type="success"
              icon="el-icon-location"
              size="mini"
              @click="showExpress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
      <!-- 表格区域 结束 -->
    </el-card>
    <!-- 卡片区域 结束 -->
    <!-- 修改地址对话框区域 开始 -->
    <el-dialog title="修改地址" :visible.sync="editDialogVisible" width="50%">
      <el-cascader
        v-model="citySelect"
        :options="citydata"
        :props="{ expandTrigger: 'hover' }"
        @change="handleChange"
      ></el-cascader>
      <span slot="footer" class="dialog-footer">
        <el-button @click="editDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="editDialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 修改地址对话框区域 结束 -->
    <!-- 物流进度对话框 开始 -->
    <el-dialog
      title="物流进度"
      :visible.sync="expressDialogVisible"
      width="50%"
    >
      <el-timeline :reverse="reverse">
        <el-timeline-item
          v-for="(item, index) in expressList"
          :key="index"
          :timestamp="item.time"
        >
          {{ item.content }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
    <!-- 物流进度对话框 结束 -->
  </div>
</template>

<script>
import citydata from './citydata'
export default {
  data() {
    return {
      // 对话框
      editDialogVisible: false,
      expressDialogVisible: false,
      // 获取商品列表参数
      query: {
        pagenum: 1,
        pagesize: 10
      },
      // 商品列表
      ordersList: [],
      // 数据总条数
      total: 0,
      citySelect: [],
      citydata,
      expressList: [],
      reverse: true
    }
  },

  created() {
    this.getOrderList()
  },

  methods: {
    // 获取订单列表
    async getOrderList() {
      const res = await this.$axios.get('/orders', {
        params: this.query
      })
      if (res.meta.status !== 200) {
        return this.$message.error('获取订单列表失败')
      }
      this.ordersList = res.data.goods
      this.total = res.data.total
      this.$message.success('获取订单列表成功')
    },
    async showExpress() {
      this.expressDialogVisible = true
      const res = await this.$axios.get('http://localhost:8080/api/express')
      if (res.meta.status !== 200) {
        return this.$message.error('获取物流进度失败')
      }
      this.expressList = res.data
    },
    handleChange() {}
  }
}
</script>

<style scoped lang='less'>
</style>
